package com.cool.service.impl;

import com.cool.dao.PersonAttributeMapper;
import org.apache.logging.log4j.util.PropertiesUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.ldap.filter.AndFilter;
import org.springframework.ldap.filter.EqualsFilter;
import org.springframework.ldap.support.LdapNameBuilder;
import org.springframework.stereotype.Service;

import javax.naming.Name;
import java.util.List;


@Service
public class LdapProvider {
    @Autowired
    LdapTemplate ldapTemplate;

    public void test() {
        List<Person> list = ldapTemplate.findAll(Person.class);
        System.out.println(111);
    }

    public void updatPerson(String name) {
        AndFilter filter = new AndFilter();
        filter.and(new EqualsFilter("objectClass", "person"));
        filter.and(new EqualsFilter("sAMAccountName", "sunjt"));


        List<Person> search = ldapTemplate.search("", filter.encode(), new PersonAttributeMapper());
        System.out.println(search);
    }

    //CN=贾韶旭,OU=投资管理部,OU=战略投资管理中心
    private Name buildDn(Person user) {
        return LdapNameBuilder.newInstance()
                .add("CN", "贾韶旭")
                .add("OU", "投资管理部")
                .add("OU", "战略投资管理中心")
                .build();
    }

}
